$(function () {


    $('#shijianyi').datetimepicker({
        //viewMode: 'day',
        format: 'YYYY-MM-DD'
    });
    $('#shijianer').datetimepicker({
        format: 'YYYY-MM-DD',
        useCurrent: false //Important! See issue #1075
    });
    $("#shijianyi").on("dp.change", function (e) {
        $('#shijianer').data("DateTimePicker").minDate(e.date);
    });
    $("#shijianer").on("dp.change", function (e) {
        $('#shijianyi').data("DateTimePicker").maxDate(e.date);
    });


    $('#riqi').datetimepicker({
        //viewMode: 'day',
        format: 'YYYY-MM-DD'
    });
    $('#Sriqi').datetimepicker({
        //viewMode: 'day',
        format: 'YYYY-MM-DD'
    });


    $('#table').bootstrapTable({
        url: '${pageContext.request.contextPath}/../../lvhua/quanbujianyi',
        columns: [{
            field: '0',
            title: 'id',
            visible : false,
        },{
            field: '1',
            title: '单据编号'
        },{
            field: '3',
            title: '类型'
        },{
            field: '2',
            title: '区域'
        },{
            field: '4',
            title: '负责人'
        },{
            field: '5',
            title: '日期'
        }, {
            field : '6',
            title : '合格'
        },{
            field:'7',
            title:'描述'
        },{
            field : 'xx',
            title : '操作',
            formatter:function(value,row,index){
                return "<a href='javascript:del("+row[0]+")'>删除</a>" ;
            }
        }],
        contentType : "application/x-www-form-urlencoded",
        queryParamsType:'',
        height:680,
        queryParams: queryParams,
        pageList:[1,10,15],
        pageNumber:1,
        pageSize:15,
        pagination:true,
        sidePagination:'server',

        onDblClickRow: function (row, $element, field) {
            $("#myModal2").modal("show");

            $("#yin1").val(row[0]);
            $("#Sorder").val(row[1]);
            $("#Squyu").val(row[2])
            $("#Sfuzhuren").val(row[4])
            $("#Sriqi").val(row[5])
            $("#Syanshou").val(row[6])
            $("#Smiaoshu").val(row[7])
        },





    });



})

//按条件查询
function ban(){
    var opt = $("#table").bootstrapTable('getOptions') ;
    var firstDate = $("#shijianer").val() ;
    var secondDate = $("#shijianyi").val() ;
    var zhuangtai = $('#Ssjtype').val();

    $.post('${pageContext.request.contextPath}/../../lvhua/quanbujianyi',{'type':zhuangtai,'pageNumber':opt.pageNumber,'pageSize':opt.pageSize,'firstDate':firstDate,'secondDate':secondDate},function(data){
        //重新给table绑定数据5
        $("#table").bootstrapTable("load",data) ;
    }) ;
}

function queryParams(params) {
    var temp = {  //这里的键的名字和控制器的变量名必须一直，这边改动，控制器也需要改成一样的
        'pageSize': params.pageSize,  //页面大小
        'pageNumber': params.pageNumber, //页码
        'secondDate':$("#shijianyi").val(),
        'firstDate':$("#shijianer").val(),
        'type': $("#Ssjtype").val(),
    };
    return temp;
};
//删除
function del(id) {
    var id=id;
    var opt = $("#table").bootstrapTable('getOptions') ;
    $.post("${pageContext.request.contextPath}/../../lvhua/Qdel",{"id":id,"pageNumber":opt.pageNumber,'pageSize':opt.pageSize},function (data) {
        $("#table").bootstrapTable("load",data);
    })
}

//增加数据
function add2() {
    var opt = $("#table").bootstrapTable('getOptions');

    var order = $("#order").val();


    var type = $("#sjtype").val();

    var address = $("#quyu").val();

    var name=$("#fuzheren").val();

    var date = $("#riqi").val();

    var ys=$("#yanshou").val();

    var remark=$("#miaoshu").val();
    $.post("${pageContext.request.contextPath}/../../lvhua/Qtianjia",{"remark":remark,"order":order,"type":type,"address":address,"date":date,"name":name,"ys":ys,"pageNumber":opt.pageNumber,"pageSize":opt.pageSize},function (data) {
        $("#table").bootstrapTable("load",data);
    })
}

//修改数据
function upd() {
    var opt = $("#table").bootstrapTable('getOptions');

    var order = $("#Sorder").val();

    var type = $("#SSsjtype").val();


    var address = $("#Squyu").val();
    var name=$("#Sfuzhuren").val();

    var date = $("#Sriqi").val();


    var ys=$("#Syanshou").val();

    var remark=$("#Smiaoshu").val();

    var yin1 = $("#yin1").val();
    $.post("${pageContext.request.contextPath}/../../lvhua/Qupd",{"id":yin1,"order":order,"name":name, "address":address,"date":date,"ys":ys,"remark":remark,"type":type,"pageNumber":opt.pageNumber,"pageSize":opt.pageSize},function (data) {
        $("#table").bootstrapTable("load",data);
    })
}











